#include "GraphPredicates.hpp"
#include "GraphHandler.hpp"

void Vertex_writer::operator() (std::ostream& out, const GraphHandler::Vertex& v) const
{
    //using namespace boost;
    //using namespace std;
    bool bMatch0 = false;
    bool bMatch1 = false;
    bool bMatch2 = false;
    std::string sName = GraphHandler::Instance().m_IDTypes[
            boost::get(boost::vertex_name, graph, v) ];
    if( m_pOverlaygraph.size() == 0 )
        out << "[label=\"" << sName << "\"]";
    else
    {
        unsigned char R = 0, G = 0, B = 0, A = 255;

        for(int j=0; j < m_pOverlaygraph.size(); j++)
        {
        // Check if we can find this vertex in the overlay graph, if so, color red.
        typedef boost::graph_traits<GraphHandler::Graph>::vertex_iterator Iter_T;
        Iter_T vi1, vi_end1;
        for (boost::tie(vi1, vi_end1) = boost::vertices(*m_pOverlaygraph[j]); vi1 != vi_end1; ++vi1)
            if(boost::get(boost::vertex_name, graph, v) == boost::get(boost::vertex_name, *m_pOverlaygraph[j], *vi1) )
                {
                    if( j == 0 ) {R = 255; bMatch0 = true; }
                    else if( j == 1 ) { bMatch1 = true;  }
                    else if ( j==2 ) {bMatch2 = true;  }
                }
        }

        if(m_pOverlaygraph.size() == 3)
        {
        // Green means its predicted and in the actual graph but not observed yet
        if(bMatch1 && bMatch2 && !bMatch0)
        { R = 0; G = 255; B = 0; }

        // Red means its predicted but not in the actual graph
        if(bMatch1 && !bMatch2 && !bMatch0)
        { R = 255; G = 0; B = 0; }

        // Yellow means its in the partial graph but not in the hypothesis
        if(bMatch0 && !bMatch1)
        { R = 255; G = 255; B = 0; }

        // Blue means its in the hypothesis, observed
        if(bMatch0 && bMatch2 && bMatch1)
        { R = 0; G = 0; B = 255; }

        // Black is normal color
        if(!bMatch0 && !bMatch1 && !bMatch2)
        { R = 0; G = 0; B = 0; }
        }

        /*
        // Black is normal color
        if(!bMatch0 && !bMatch1 && !bMatch2)
        { R = 0; G = 0; B = 0; }*/

        out << "[label=\"" << sName << "\"," <<  //graph[v].sName << "\"," <<
        "color=\"#" << hex(R) << hex(G) << hex(B) << hex(A) << "\"]";
        out << std::dec;
    }
}
